import { postMusic, putMusic, getMusic } from '@/base/api/MusicApi';
import { Music } from '@/base/model/Music';
export class FormBloc {
  form: any = {
    id: 0,
    musicName: '',
    englishName: '',
    musicUrl: '',
    imgUrl: '',
    code: 0,
  };
  fileList: Array<any> = [];

  saveMusic() {
    if (this.form.id === 0) {
      return postMusic(this.form)
    } else {
      return putMusic(this.form)
    }
  }

  getMusicById(id: number) {
    return getMusic(id)
      .then((res) => {
        let dataItem = res.data;
        this.form.id = dataItem.id;
        this.form.musicName = dataItem.musicName;
        this.form.englishName = dataItem.englishName;
        this.form.musicUrl = dataItem.musicUrl;
        this.form.imgUrl = dataItem.imgUrl;
        this.form.code = dataItem.code;
        this.fileList.push(dataItem.imgUrl);
        return res;
      })
  }
}
